public class TestDemo{
    //投票法找多数元素
    public static void main1(String[] args) {
        int[] arr = {2, 2, 1, 3, 7, 2, 2};

        int count = 0;
        int vote = 0;

        for (int i : arr) {
            if (count == 0) {
                vote = i;
                count++;
                continue;
            }
            if (i == vote) {
                count++;
            } else {
                count--;
            }
        }
        System.out.println(vote);
    }
}